﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import flash.events.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.controllers.startup.*;

    public class TrackingCommand extends Command {

		[Inject]
        public var event:TrackingEvent;
		[Inject]
        public var environmentModel:EnvironmentModel;
		[Inject]
        public var userModel:UserModel;
		[Inject]
        public var friendsModel:FriendsModel;
		[Inject]
        public var energyModel:EnergyModel;
		[Inject]
        public var sessionModel:SessionModel;
		[Inject]
        public var gameViewModel:GameViewModel;

        override public function execute():void{
            switch (this.event.parameter){
                case TrackingConst.SET_LEVEL:
                    this.trackSetLevel();
                    break;
                case TrackingConst.LOADING:
                    this.trackLoading();
                    break;
                case TrackingConst.BUY_DECO:
                    this.trackBuyDeco();
                    break;
                case TrackingConst.EVENT:
                    this.trackEvent();
                    break;
                default:
                    this.trackDefault();
            };
        }
        private function trackDefault():void{
            this.sendRequest(this.event.parameter, this.event.info);
        }
        private function trackSetLevel():void{
            var _local1:Object = new Object();
            _local1.friends = this.friendsModel.friends.length;
            this.sendRequest(TrackingConst.SET_LEVEL, _local1);
        }
        private function trackLoading():void{
            var _local1:Object = new Object();
            _local1.progress = this.event.info.progress;
            _local1.elapsed = this.event.info.elapsed;
            this.sendRequest(TrackingConst.LOADING, _local1);
        }
        private function trackBuyDeco():void{
            var _local1:Object = new Object();
            _local1.type = this.event.info.type;
            _local1.price_coins = this.event.info.price_coins;
            this.sendRequest(TrackingConst.BUY_DECO, _local1);
        }
        private function trackEvent():void{
            var _local1:Object = ((this.event.info) || ({}));
            this.sendRequest(TrackingConst.EVENT, _local1);
        }
        private function sendRequest(_arg1:String, _arg2:Object):void{
            _arg2.s = this.userModel.mySocialID;
            _arg2.language = this.environmentModel.locale;
            _arg2.xp = this.userModel.xpPoints;
            _arg2.userlevel = this.userModel.level;
            _arg2.coins = this.userModel.coins;
            _arg2.zoom = this.gameViewModel.gameViewScale;
            _arg2.energy = (this.energyModel.energy + this.energyModel.energyExtra);
            _arg2.ab_test = this.sessionModel.abTest;
            _arg2.variant = this.sessionModel.variant;
            _arg2.random = new Date().valueOf();
            var _local3 = ((this.environmentModel.tracking_url + _arg1) + "/");
            var _local4:RequestEvent = new RequestEvent(EventConstants.SEND_REQUEST);
            _local4.errorHandler = this.onError;
            _local4.addRequest(_local3, _arg2, false, GameConstants.SWF);
            dispatch(_local4);
        }
        private function onError(_arg1:Event):void{
            dispatch(new InfoEvent(EventConstants.REPORT_PROBLEM, null, _arg1));
        }

    }
}//package net.wooga.pets.controllers 
